foreach x in B01002 B02001 B15003 B19013 {
	clear
	tempfile `x'file
	save ``x'file', emptyok 
forvalues y = 2014 / 2017 {
	clear
	import delimited using "$ACS/ACSDT5Y`y'.`x'-Data.csv", varn(1)
	gen year = `y'
	append using ``x'file'
	save ``x'file', replace
}
gen cbg = substr(geo_id,10,12)
destring cbg, force replace
format cbg %15.0g
save ``x'file', replace
}

use `B01002file', clear
merge 1:1 year cbg using `B02001file'
drop _merge
merge 1:1 year cbg using `B15003file'
drop _merge
merge 1:1 year cbg using `B19013file'
drop _merge

order year cbg
keep year cbg  b01002_001e b02001_001e b02001_002e b15003_001e b15003_022e b15003_023e b15003_024e b15003_025e b19013_001e

destring b01002_001e b02001_001e b02001_002e b15003_001e b15003_022e b15003_023e b15003_024e b15003_025e b19013_001e, force replace

gen BA_fraction = (b15003_022e + b15003_023e + b15003_024e + b15003_025e) / b15003_001e
gen white_frac = b02001_002e/ b02001_001e
label var b01002_001e "Median Age"
label var white_frac "Fraction White" 
label var BA_fraction  "Fraction with BA or greater"
label var b19013_001e "Median Income"

tempfile temp
save "${Data_Clean}/panel_demog.dta", replace
